<template>
  <el-row class="rt">
    <el-col :span="2">患者信息</el-col>
    <el-col :span="22">
      <span class="s">姓名:{{patient.realName}}</span>
      <span class="s">病历号:{{patient.caseNumber}}</span>
      <span class="s">年龄:{{patient.age}}</span>
      <span class="s">性别:{{patient.gender}}</span>
    </el-col>
  </el-row>
  <el-row>
    <el-col>
    检验申请
    </el-col>
  </el-row>
  <el-row>
    <el-col>
      项目总计<el-input  style="width: 100px;height: 65px"  disabled :placeholder="money"/>
    </el-col>
  </el-row>
  <el-row>
    <table class="rt">

        <td>
          <el-table :data="changeList" @selection-change="testCodeList">
            <el-table-column type="selection" width="55" />
            <el-table-column prop="techCode" label="检验编码"></el-table-column>
            <el-table-column prop="techName" label="检验名称"></el-table-column>
            <el-table-column prop="techType" label="检验规格"></el-table-column>
            <el-table-column prop="techPrice"  label="单价"></el-table-column>
            <el-table-column prop="priceType"  label="费用分类"></el-table-column>
            <el-table-column>
              <template #header>
                <el-button link type="primary">删除</el-button>
                <el-button link type="primary" @click="centerDialogVisible=true">添加</el-button>
              </template>
            </el-table-column>
          </el-table>

        </td>
      <tr>
        <el-row>
          <el-col :span="3"><td>目的要求</td></el-col>
          <el-col :span="21"><td><el-input v-model="medicalList2.inspectionInfo" :rows="3" type="textarea"></el-input></td></el-col>
        </el-row>
      </tr>
      <tr>
        <el-row>
          <el-col :span="3"><td>检验部位</td></el-col>
          <el-col :span="21"><td><el-input v-model="medicalList2.inspectionPosition" :rows="3" type="textarea"></el-input></td></el-col>
        </el-row>
      </tr>
      <tr>
        <el-row>
          <el-col :span="3"><td>备注</td></el-col>
          <el-col :span="21"><td><el-input v-model="medicalList2.inspectionRemark" :rows="3" type="textarea"></el-input></td></el-col>
        </el-row>
      </tr>
      <tr>
        <td colspan="2">
          <el-button @click="changeMedical" type="primary">保存</el-button>
          <el-button type="primary">清空</el-button>
        </td>
      </tr>
    </table>
  </el-row>
  <el-row>
    <el-pagination></el-pagination>
  </el-row>
  <el-dialog v-model="centerDialogVisible" title="添加疾病诊断" width="30%" center>
    <el-row class="dr">
      <el-col  :span="4">检验名称</el-col>
      <el-col :span="20"><el-input v-model="tname"/></el-col>
    </el-row >
    <el-row class="dr">
      <el-col  :span="4">检验编号</el-col>
      <el-col :span="20"><el-input v-model="tcode"/></el-col>
    </el-row>
    <el-row class="dr">
      <el-col :span="24" style="text-align: right">
        <el-button @click="techList">搜索</el-button>
      </el-col>
    </el-row>
    <el-table :data="techlist"  @selection-change="handleSelectionChange"
              ref="tableRef"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="techCode" label="检验编码"></el-table-column>
      <el-table-column prop="techName" label="检验名称"></el-table-column>
      <el-table-column prop="techType" label="检验规格"></el-table-column>
      <el-table-column prop="techPrice"  label="单价"></el-table-column>
      <el-table-column prop="priceType"  label="费用分类"></el-table-column>
    </el-table>
    <el-row>
      <el-row :span="24" >
        <el-pagination style="margin: 0px auto" @current-change="doPaging" :page-size="TotalRowInfo.pageSize" background layout="prev, pager, next" :total="TotalRowInfo.TotalRow" />
      </el-row>
    </el-row>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="changOk">提交</el-button>
        <el-button type="primary" @click="Deselect">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>

import {ElMessage} from "element-plus";

export default {
  name: "test",
  data(){
    return{
      centerDialogVisible:false,
      patient:{},
      changeList:[],
      changeListCopy:[],
      tname:'',
      tcode:'',
      techlist:[],
      TotalRowInfo:{TotalRow:0,pageSize:10,currentPage:1},
      money:0,
      moneycopy:0,
      medicalList2:{},
      tidArr:[],

    }
  },
  methods: {
    testCodeList(arr){
      this.tidArr=[]
      for (let i in arr){
        this.tidArr.push(arr[i].id)
      }
      this.moneycopy=0
      for (let i=0;i<arr.length;i++){
        if (!isNaN(arr[i].techPrice)){
          this.moneycopy += arr[i].techPrice
          console.log(arr[i].techPrice)
        }
      }

      console.log(this.moneycopy)
      this.money=JSON.parse(JSON.stringify(this.moneycopy))
    },
    changeMedical(){
      this.medicalList2.registerId = this.patient.id
      let str=this.$qs.stringify(this.medicalList2)
      this.$axios.get("http://localhost:8080/InspectionRequest/insert?"+str+"&tids="+this.tidArr+"&id="+this.patient.id).then((res) => {
        if(res.data){
          ElMessage.success("保存成功")
        }else {
          ElMessage.error("保存失败")
        }

      })
    },
    Deselect(){
      this.$refs.tableRef.clearSelection()
      this.moneycopy=0
    },
    handleSelectionChange(darr){
      this.changeListCopy=darr

    },
    changOk() {
      this.changeList=JSON.parse(JSON.stringify(this.changeListCopy))


      console.log(this.moneycopy)
      this.centerDialogVisible = false
    },
    techList(){

      this.$axios.get("http://localhost:8080/Technology/list?ps="+this.TotalRowInfo.pageSize+"&cur=1"+"&techName="+this.tname+"&techCode="+this.tcode).then((res) => {
        console.log(res.data)
        this.techlist=res.data
        this.$axios.get("http://localhost:8080/Technology/TotalRow").then((res) => {
          this.TotalRowInfo.TotalRow=res.data

        })
      })

    },
    doPaging(cur){
      this.TotalRowInfo.currentPage=cur
      this.$axios.get("http://localhost:8080/Technology/list?ps="+this.TotalRowInfo.pageSize+"&cur="+cur+"&techName="+this.tname+"&techCode="+this.tcode).then((res) => {
        console.log(res.data)
        this.techlist=res.data

      })
    }
  },

  created() {
    let md1 = new Date();
    let year1 = md1.getFullYear();
    let m1 = md1.getMonth()+1;
    m1 = m1<10?'0'+m1:m1;
    let r1 = md1.getDate();
    r1 = r1<10?'0'+r1:r1;
    let x1 = md1.getHours()+1;
    x1 = x1<10?'0'+x1:x1;
    let f1 = md1.getMinutes();
    f1 = f1<10?'0'+f1:f1;
    let t1 = md1.getSeconds();
    let inspectionTime =year1 + '-' + m1 + '-' + r1 + '-' + x1 + '-' + f1 + '-' + t1;
    let md2 = new Date();
    let year2 = md2.getFullYear();
    let m2 = md2.getMonth()+1;
    m2 = m2<10?'0'+m2:m2;
    let r2 = md2.getDate();
    r2 = r2<10?'0'+r2:r2;
    let x2 = md2.getHours();
    x2 = x2<10?'0'+x2:x2;
    let f2 = md2.getMinutes();
    f2 = f2<10?'0'+f2:f2;
    let t2 = md2.getSeconds();
    let creationTime =year2 + '-' + m2 + '-' + r2 + '-' + x2 + '-' + f2 + '-' + t2;

    this.patient = JSON.parse(sessionStorage.getItem("r"))
    let emp= JSON.parse(sessionStorage.getItem("emp"))
    this.medicalList2.inspectionEmployeeId=emp.id
    this.medicalList2.inputinspectionEmployeeId=emp.id
    this.medicalList2.creationTime=creationTime
    this.medicalList2.inspectionTime=inspectionTime

    if (this.patient.registMoney>=this.money){
      this.medicalList2.inspectionState='已缴费'
    }else {
      this.medicalList2.inspectionState='未缴费'
    }
    console.log(emp.registMoney)
    console.log(inspectionTime)
    console.log(this.patient)
  }
}
</script>

<style scoped>
*{
  text-align: left;
  font-size: 14px;
}
.el-row:nth-child(1){
  border: none;
  margin:0px;
  padding:0px;
}
.el-row:nth-child(1) span{
  display: inline-block;
  line-height: 30px;
}
.f1{
  background-color: #F0F9EB;
  color: #67C23A;
}
.l2{
  background-color: #FDF6EC;
  color: #E7AAA8;
}


.el-row{
  border-top: solid 1px lightgray;
  line-height: 60px;
}

.rt{
  width: 60%;
  text-align: left;
  color: #909399;
}
.rt .el-input{
  height: 40px;
  width: 95%;
}
</style>